package zhengyanze.com.aipoemmax.guide.guide;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.rd.PageIndicatorView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import zhengyanze.com.aipoemmax.R;

public class GuideActivity extends AppCompatActivity {
    @BindView(R.id.vp)
    ViewPager vp;
    ArrayList<Fragment> mFragments;
    String[] title = new String[]{
            "触", "动"
            , "潇", "洒"
            , "爱", "慕",};
    String[] content = new String[]{
            "你是无意穿堂风", "却偏偏引山洪"
            , "人生得意须尽欢", "莫使金樽空对月"
            , "山有木兮木有枝", "心悦君兮君不知"};
    @BindView(R.id.pageindicator)
    PageIndicatorView pageindicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_guide);
        ButterKnife.bind(this);
        mFragments = new ArrayList<>();
        initData();

        GuideAdadpter mAdapter = new GuideAdadpter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        vp.setOffscreenPageLimit(mFragments.size());
        pageindicator.setViewPager(vp);
    }

    /**
     * 初始化数据
     */
    public void initData() {
        GuideFragment fragment1 = new GuideFragment();
        fragment1.setText(new String[]{title[0], title[1]}, new String[]{content[0], content[1]}
                                ,R.mipmap.splash_guide_bg_1);
        GuideFragment fragment2 = new GuideFragment();
        fragment2.setText(new String[]{title[2], title[3]}, new String[]{content[2], content[3]}
                ,R.mipmap.splash_guide_bg_2);
        GuideFragment fragment3 = new GuideFragment();
        fragment3.setText(new String[]{title[4], title[5]}, new String[]{content[4], content[5]}
                ,R.mipmap.splash_guide_bg_3);

        mFragments.add(fragment1);
        mFragments.add(fragment2);
        mFragments.add(fragment3);
        mFragments.add(new GuideFragment2());
    }

    /**
     * ViewPager适配器
     */
    class GuideAdadpter extends FragmentPagerAdapter {
        public GuideAdadpter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    }
}
